﻿namespace EyeOpen.SerialPort.Shell
{
	using System;
	using System.Collections.Generic;
	using System.IO.Ports;
	using System.Threading;

	using EyeOpen.IO;
	using EyeOpen.IO.Ports;
	using EyeOpen.SerialPort.Test;

	internal class Program
	{
		public static void Main()
		{
			var logger = new ConsoleLogger();

			////var serialPort =
			////    new PhysicalSerialPort(
			////        new ChannelConfiguration("COM4", 4800, 8, Parity.None, StopBits.One),
			////        logger);

			var serialPort1 = 
				new FakePort(
					new ChannelConfiguration("COM4", 4800, 8, Parity.None, StopBits.One), 
					logger);

			var rs232 = new Rs232(serialPort1, logger);

			var channels = 
				new List<IChannel>
					{
						rs232,
					};

			foreach (var channel in channels)
			{
				if (channel.State == ChannelState.Closed)
				{
					channel.OpenChannel();
				}

				Thread.Sleep(2000);

				if (channel.State == ChannelState.Open)
				{
					channel.Send("7E0401FF02620164");

					Thread.Sleep(2000);

					if (channel.State == ChannelState.Open || channel.State == ChannelState.Connected)
					{
						channel.CloseChannel();
					}
				}

				Console.WriteLine();
			}

			Console.ForegroundColor = ConsoleColor.Red;
			Console.WriteLine("End");
			Console.ReadLine();
		}
	}
}